package com.jm.programming.stream;

import com.jm.programming.stream.pojo.Author;
import com.jm.programming.stream.utils.CreateDataUtil;

import java.util.List;
import java.util.function.Predicate;

/**
 * @Description
 * @date 2022/7/7 15:20
 */
public class StreamInterMain {
    public static void main(String[] args) {

    }

    /**
     * 输出年龄大于17且姓名长度大于1的作家
     */
    static void getAuthors(){
        List<Author> authors = CreateDataUtil.getAuthors();
                authors.stream()
                        .distinct()
                        .filter(((Predicate<Author>)  author -> author.getAge() > 17).and( author -> author.getName().length() > 1))
                        .forEach(author -> System.out.println(author));
    }

    /**
     * 输出年龄大于17或者姓名长度小于2的作家
     */
    static void getAuthors2(){
        List<Author> authors = CreateDataUtil.getAuthors();
        authors.stream()
                .distinct()
                .filter(((Predicate<Author>)  author -> author.getAge() > 17)
                        .or( author -> author.getName().length() < 2))
                .forEach(author -> System.out.println(author));
    }

    /**
     * 输出年龄不大于17的作家
     */
    static void getAuthors3(){
        List<Author> authors = CreateDataUtil.getAuthors();
        authors.stream()
                .distinct()
                .filter(((Predicate<Author>)  author -> author.getAge() > 17)
                        .negate())
                .forEach(author -> System.out.println(author));
    }
}
